#ifndef SH_UUID_HPP
#define SH_UUID_HPP

#include <string>
#include <cstdio>
#if defined(_WIN32) || defined(_WIN64)
#include <objbase.h>
#elif defined(linux)
//cmakelist.txt link  -luuid
#include <uuid/uuid.h>
#else
#error "no support uuid"
#endif

#define GUID_LEN 64

namespace sh
{
class UUID
{
public:
#if defined(_WIN32) || defined(_WIN64)
    static std::string uuid()
    {

        char buf[GUID_LEN] = {0};
        GUID guid;

        if (CoCreateGuid(&guid))
        {
            return std::string("");
        }
        sprintf(buf,
                "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X",
                guid.Data1, guid.Data2, guid.Data3,
                guid.Data4[0], guid.Data4[1], guid.Data4[2],
                guid.Data4[3], guid.Data4[4], guid.Data4[5],
                guid.Data4[6], guid.Data4[7]);
        return std::string(buf);
    }
#else
    static std::string uuid()
    {
        uuid_t uu;
        uuid_generate(uu);
        char buf[37] = {'\0'};
        uuid_unparse_upper(uu, buf);
        return std::string(buf);
    }
#endif
};
}

#endif //SH_UUID_HPP
